package sr.codemg.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sr.codemg.entity.SysRoleMenu;
import sr.codemg.mapper.SysRoleMenuMapper;
import sr.codemg.service.SysRoleMenuService;
import sr.codemg.utils.Constants;
import sr.codemg.utils.ResponseCode;
import sr.codemg.utils.StaticFunc;
import sr.codemg.vm.Base;
import sr.codemg.vm.Selects;
import sr.codemg.vm.SysRoleMenuData;
import sr.codemg.vm.Tables;

import java.util.List;
import java.util.Map;

/**
 * 权限菜单信息
 **/
@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {

    @Autowired
    SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public SysRoleMenu get(String roleId, String menuId) {
        return sysRoleMenuMapper.get(roleId, menuId);
    }

    @Override
    public Tables findList(Map<String, Object> params) {
        StaticFunc.page(params);
        List<SysRoleMenuData> data = sysRoleMenuMapper.findList(params);
        Integer count = sysRoleMenuMapper.count(params);
        return new Tables(data, count);
    }

    @Override
    public Base.Response add(SysRoleMenu entity) {
        sysRoleMenuMapper.add(entity);
        return ResponseCode.getBase(Constants.SUCC);
    }

    @Override
    public Base.Response update(SysRoleMenuData entity) {
        SysRoleMenu item = sysRoleMenuMapper.get(entity.getRoleId(), entity.getMenuId());
        item.setButtonIds(entity.getButtonIds());
        sysRoleMenuMapper.update(entity);
        return ResponseCode.getBase(Constants.SUCC);
    }

    @Override
    public Base.Response delete(String id) {
        sysRoleMenuMapper.delete(id);
        return ResponseCode.getBase(Constants.SUCC);
    }

    @Override
    public Selects.Response select(Selects.Request req) {
        req.configPage();
        List<Selects.Select> data = sysRoleMenuMapper.select(req);
        Selects.Response res = new Selects.Response();
        res.setData(data);
        return res;
    }
}

